import requests
from utils import get_mongo_collection
import time,config
"""
根据mid关注对应的人'finger=6b9435fe; LIVE_BUVID=AUTO5215235378221534; fts=1523537824; sid=7pfw0ygr; DedeUserID=278341012; DedeUserID__ckMd5=900d3f01ad531e71; SESSDATA=c472106b%2C1526129828%2C2251bb72; bili_jct=5960be85c4b713ed71e2a7e9e10ffc47; UM_distinctid=162b9ee87a8d0-093dd45941c1ae-3a76015a-1fa400-162b9ee87a97ef; buvid3=52924E99-2C76-47C4-8258-70F406447F07103072infoc; rpdid=iwqqxmmlmqdosiksqmqxw; im_notify_type_278341012=0; CURRENT_QUALITY=64; _dfcaptcha=36edc254f77caf1b29907f31560b187a'


"""

headers = {
    'Cookie':config.BILIBILICOOKIE,
    'Host': 'api.bilibili.com',
    'Referer': 'https://space.bilibili.com/4543111/',
    'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36'
}

def get_mids():
    mids = []
    mid_model = get_mongo_collection('feed').find({"purpose": "B站UP主"})
    for i in mid_model:
        mids.append(i['mid'])
    return mids


def main():
    for mid in get_mids():
        params = {'fid': mid, 'act': 1, 're_src': 11, 'jsonp': 'jsonp', 'csrf': 'c59002d60be68bc9362f9bfe209077c3'}
        a=requests.post('https://api.bilibili.com/x/relation/modify', params=params, headers=headers)
        time.sleep(5)
        print(a.text)


if __name__ == '__main__':
    main()
